package org.qiandaosystem.qiandaosystemsource.dto;

import lombok.Data;
import org.qiandaosystem.qiandaosystemsource.entity.SignActivity;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.List;

@Data
public class SignActivityStatisticsDTO {
    private Integer activityId;
    private SignActivity.SignType type;
    private LocalDateTime startTime;
    private LocalDateTime endTime;
    private String timeStatus; // 剩余时间或已截止
    private Long remainingMinutes; // 剩余分钟数，如果已截止则为null
    
    private Integer totalStudents; // 总学生数
    private Integer signedCount; // 已签到人数
    private Integer unsignedCount; // 未签到人数
    
    private List<StudentSignInfo> signedStudents; // 已签到学生列表
    private List<StudentSignInfo> unsignedStudents; // 未签到学生列表
    
    @Data
    public static class StudentSignInfo {
        private Integer userId;
        private String username;
        private String realName;
        private LocalDateTime signTime; // 签到时间，未签到学生为null
    }
    
    public void calculateTimeStatus() {
        LocalDateTime now = LocalDateTime.now();
        if (now.isAfter(endTime)) {
            this.timeStatus = "已截止";
            this.remainingMinutes = null;
        } else {
            Duration duration = Duration.between(now, endTime);
            this.remainingMinutes = duration.toMinutes();
            this.timeStatus = String.format("剩余%d小时%d分钟", 
                this.remainingMinutes / 60, 
                this.remainingMinutes % 60);
        }
    }
} 